package com.gang.conf;

import org.fisco.bcos.sdk.BcosSDK;
import org.fisco.bcos.sdk.client.Client;
import org.fisco.bcos.sdk.crypto.keypair.CryptoKeyPair;
import org.fisco.bcos.sdk.transaction.manager.AssembleTransactionProcessor;
import org.fisco.bcos.sdk.transaction.manager.TransactionProcessorFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.security.KeyPair;
import java.util.ArrayList;
import java.util.List;

@Component
public class FiscoSDK {

    @Autowired
    FiscoBcos fiscoBcos;

    AssembleTransactionProcessor transactionProcessor;
    public AssembleTransactionProcessor getTransactionProcessor() {
        BcosSDK bcosSDK = fiscoBcos.getBcosSDK();
        Client client = bcosSDK.getClient(Integer.valueOf(1));
        CryptoKeyPair keyPair = client.getCryptoSuite().createKeyPair();

        List list = new ArrayList();
        list.add("hello,bro");
        try {
            transactionProcessor= TransactionProcessorFactory.createAssembleTransactionProcessor(client, keyPair, "src/main/resources/abi/", "");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return transactionProcessor;
    }

    public Client getClient(){
        BcosSDK bcosSDK = fiscoBcos.getBcosSDK();
        return bcosSDK.getClient(Integer.valueOf(1));
    }
}
